﻿Imports lbGlobalcom
Public Class fFacturasRecargaPasatiempo
    Dim daRec As lbGlobalcom.dsFacturacionTableAdapters.FAC_PORCENTAJEBASETableAdapter
    Private Sub btnGenerarFacturas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub


    Private Sub fFacturasRecargaPasatiempo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daRec = New lbGlobalcom.dsFacturacionTableAdapters.FAC_PORCENTAJEBASETableAdapter
            daRec.Fill(DsFacturacion.FAC_PORCENTAJEBASE)
            cbPorcentaje.SelectedValue = 0
        Catch ex As Exception
            lbGlobalcom.cError.SalvaError(ex, "Henry")
            MessageBox.Show(ex.Message)
        End Try
    End Sub


    Private Sub btnBuscaProducto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaProducto.Click
        Try
            Dim flPro As New fListaProductos
            If flPro.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtIdProducto.Text = flPro.idArticulo
                lbNombre.Text = ""
            End If
        Catch ex As Exception
            lbGlobalcom.cError.SalvaError(ex, "Henry")
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnBuscaDoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaDoc.Click
        Try
            Dim fLDoc As New fListaTipoDocs
            fLDoc.SubClase = "VEN"
            If fLDoc.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtDocumento.Text = fLDoc.idTipoDoc
                'CargaTipoDoc(fLDoc.idTipoDoc)
                'ConfiguraByTipoDoc()
                'ActualizaDatosDoc()
            End If
        Catch ex As Exception
            lbGlobalcom.cError.SalvaError(ex, "Henry")
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnGenerarFacturas_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerarFacturas.Click
        Try

            If txtDocumento.Text.Length > 0 And txtIdProducto.Text.Length > 0 And txtCliente.Text.Length > 0 And txtVendedor.Text.Length > 0 And txtValorPagado.Text.Length > 0 And txtIdCaja.Text.Length > 0 Then
                Dim valorRecarga As Decimal = txtValorRecarga.Text
                'txtValorPagado.Text * (cbPorcentaje.SelectedValue + 1)
                Dim tipo As Integer = 0
                If cbPorcentaje.SelectedValue = 0 Then
                    tipo = 1
                End If
                Dim cFacRec As New lbGlobalcom.cFacturasRecargaPasatiempo(txtDocumento.Text, txtIdProducto.Text, txtCliente.Text, txtSucCliente.Text, txtVendedor.Text, txtIdCaja.Text, valorRecarga, tipo)
                cFacRec.generaFacturas()
                MessageBox.Show("Se generaron facturas con exito", "Facturas", MessageBoxButtons.OK, MessageBoxIcon.Information)
                lbNumeros.DataSource = cFacRec.mlista
            Else
                MessageBox.Show("Faltan datos por ingresar", "datos", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
            lbGlobalcom.cError.SalvaError(ex, "Henry")
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnBuscaTercero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaCliente.Click
        Try
            Dim fBT As New fBuscaTercero
            fBT.TipoTercero = "Cliente"
            If fBT.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtCliente.Text = fBT.midTercero
                txtSucCliente.Text = fBT.mSucursal
                'iTerce = New cTercero(IDTERCEROTextBox.Text, "Cli")
                'iTerce.iClientes.SeekClienteBySucursal(SUCURSALTextBox.Text)
                'ActualizaDatosTercero()
            End If
        Catch ex As Exception
            lbGlobalcom.cError.SalvaError(ex, "Henry")
            MessageBox.Show(ex.Message)
        End Try
    End Sub


    Private Sub btnBuscaVendedor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaVendedor.Click
        Try
            Dim fBT As New fBuscaTercero
            fBT.TipoTercero = "Vendedor"
            If fBT.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtVendedor.Text = fBT.midTercero
                'iTerce = New cTercero(IDTERCEROTextBox.Text, "Cli")
                'iTerce.iClientes.SeekClienteBySucursal(SUCURSALTextBox.Text)
                'ActualizaDatosTercero()
            End If
        Catch ex As Exception
            lbGlobalcom.cError.SalvaError(ex, "Henry")
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        Try
            lbNumeros.DataSource = Nothing
            txtDocumento.Text = ""
            txtIdProducto.Text = ""
            txtCliente.Text = ""
            txtSucCliente.Text = ""
            txtVendedor.Text = ""
            txtValorPagado.Text = ""
            txtValorRecarga.Text = ""
        Catch ex As Exception
            lbGlobalcom.cError.SalvaError(ex, "Henry")
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub cbPorcentaje_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbPorcentaje.TextChanged
        Try
            If txtValorPagado.Text <> "" Then
                txtValorRecarga.Text = txtValorPagado.Text * (cbPorcentaje.SelectedValue + 1)
            End If
        Catch ex As Exception
            lbGlobalcom.cError.SalvaError(ex, "Henry")
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub txtValorPagado_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtValorPagado.Validated
        Try
            If txtValorPagado.Text <> "" Then
                txtValorRecarga.Text = txtValorPagado.Text * (cbPorcentaje.SelectedValue + 1)
            End If
        Catch ex As Exception
            lbGlobalcom.cError.SalvaError(ex, "Henry")
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnBuscaCaja_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaCaja.Click
        Try
            Dim flCaja As New fListaCajas
            flCaja.idSede = CustomPrincipal.IDSede
            If flCaja.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtIdCaja.Text = flCaja.caja
            End If
        Catch ex As Exception
            lbGlobalcom.cError.SalvaError(ex, "Henry")
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnImprime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImprime.Click
        Try
            For Each ItemL As String In lbNumeros.Items
                Dim ImpTirilla As lbGlobalcom.cImprimeRecargaLinea = New lbGlobalcom.cImprimeRecargaLinea(txtDocumento.Text, ItemL.Substring(0, ItemL.IndexOf("-")).Trim, My.Settings.LogoPeq, My.Settings.PrinterTirilla, My.Settings.ImprimeLogoTirilla)
                lbGlobalcom.cGeneral.MarcaDocumento(True, True, txtDocumento.Text, ItemL.Substring(0, ItemL.IndexOf("-")).Trim)
                ImpTirilla = Nothing
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class
